Interactive Map

<<<<<<< HEAD
# leaflet map for central park
fur_color <- colorFactor(c("Black","Brown","Gray"),
                               domain = nyc_squirrels_clean$primary_fur_color)

 leaflet() %>% 
  addTiles() %>% 
  fitBounds(-73.9823592,40.7636484,-73.9492441, 40.8005539)%>%
  addTiles() %>% 
  addCircleMarkers(nyc_squirrels_clean$long, 
                   nyc_squirrels_clean$lat, 
                   color = fur_color(nyc_squirrels_clean$primary_fur_color), 
                   radius = 0.5, 
                   fill = T,
                   fillOpacity = 0.2,
                   opacity = 0.6,
                   popup = nyc_squirrels_clean$primary_fur_color)
=======
>>>>>>> 3eba15ab29a9abab2517bd90a57a10b7b05b7ee2

Table

<<<<<<< HEAD
## Table 1

activity_percentages <- nyc_squirrels_clean %>% 
  select(running, chasing,climbing, eating, foraging, kuks, quaas, moans, tail_flags, tail_twitches, indifferent, runs_from) %>% 
  rownames_to_column(var = "ID") %>% 
  as.data.frame() %>% 
  pivot_longer(cols = running:runs_from, names_to = "activity",
               values_to = "true_false") %>% 
  group_by(activity) %>% 
  nest() %>% 
  mutate(proportion = map(data, ~ .x %>% 
                            pull("true_false") %>% 
                            mean())) %>% 
  unnest(proportion) %>% 
  mutate(percentage = 100*proportion) %>% 
  select(activity, percentage) %>% 
  mutate(activity = gsub("_", " ", activity),
         activity =  str_to_title(activity),
         percentage = round(percentage, 2),
         tooltip_text = paste0(toupper(activity), "\n", 
                   percentage, "%"))
=======
## Table 1

df_table <- nyc_squirrels_clean %>% 
  select(running, chasing,climbing, eating, foraging, kuks, quaas, moans, tail_flags, tail_twitches, indifferent, runs_from)

df_table_2 <- df_table %>% 
  pivot_longer(-running, names_to = "activity", values_to = "true_false")



  
chasing <- nyc_squirrels_clean %>%
  group_by(chasing) %>% 
  summarize(count = n())

climbing <- nyc_squirrels_clean %>%
  group_by(climbing) %>% 
  summarize(count = n())

eating <- nyc_squirrels_clean %>%
  group_by(eating) %>% 
  summarize(count = n())

kuks <- nyc_squirrels_clean %>%
  group_by(kuks) %>% 
  summarize(count = n())

quaas <- nyc_squirrels_clean %>%
  group_by(quaas) %>% 
  summarize(count = n())

moans <- nyc_squirrels_clean %>%
  group_by(moans) %>% 
  summarize(count = n())

tail_flags <- nyc_squirrels_clean %>%
  group_by(tail_flags) %>% 
  summarize(count = n())

tail_twitches <- nyc_squirrels_clean %>%
  group_by(tail_twitches) %>% 
  summarize(count = n())

indifferent <- nyc_squirrels_clean %>%
  group_by(indifferent) %>% 
  summarize(count = n())

runs_from <- nyc_squirrels_clean %>%
  group_by(runs_from) %>% 
  summarize(count = n())
>>>>>>> 3eba15ab29a9abab2517bd90a57a10b7b05b7ee2

Plot

activity_graph <- activity_percentages %>% 
ggplot(aes(x = percentage, 
           y = reorder(activity, percentage), 
           fill = activity,
           tooltip = tooltip_text, data_id = activity
           )) +
  geom_col_interactive(color = "black", size = 0.3) +
  labs(x = "Percentage", y = "Activity", title = "Activity Percentages") +
  theme_few() 

girafe(ggobj = activity_graph, width_svg = 6, height_svg = 3.5)

HTML Trial

my_widget <- girafe(ggobj = activity_graph, 
                    width_svg = 10, height_svg = 5) %>%
  girafe_options(opts_hover(css = "fill:cyan;"))

htmlwidgets::saveWidget(my_widget, "my_widget_page.html", 
                        selfcontained = TRUE)

Install software

remotes::install_github("hrbrmstr/albersusa")